325B - Stadium and Games - CodeForces Solution


binary search math *1800

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll MOD = 1e9+7;

#define rep(i,a,b) for(int i=a;i<b;++i) 

#define pii pair<int,int>

#define all(x) x.begin(),x.end()

#define ff first

#define ss second



set<ll> st;

ll y;



void fun(ll b,ll i)

{

    //ll disc = (ll)sqrt(b*1*1.0 + 8*y);

    ll s = (ll)sqrt(b*1.0*b + 8*y);

    if(s<b) return;

    ll x = (s-b)/2;

    if(!(x&1)) return;

    while(i--)

    x*=2;

    ll t=x,sum=0;

    while(1)

    {

        if(t&1)

        {

            sum+=(t*(t-1))/2;

            break;

        }

        sum+=(t/2);

        t/=2;

    }

    if(sum==y) st.insert(x);

}





int main()

{

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cin>>y;

    for(ll i=0;i<=62;++i)

    {

        ll t = ((1LL<<i)-1);

        fun(2*t-1,i);

    }

    if(st.empty())

    cout<<"-1\n";

    for(ll i:st)

    cout<<i<<"\n";

}


Comments

Submit
0 Comments
More Questions

156C - Cipher
545D - Queue
459B - Pashmak and Flowers
1538A - Stone Game
1454C - Sequence Transformation
165B - Burning Midnight Oil
17A - Noldbach problem
1350A - Orac and Factors
1373A - Donut Shops
26A - Almost Prime
1656E - Equal Tree Sums
1656B - Subtract Operation
1656A - Good Pairs
1367A - Short Substrings
87A - Trains
664A - Complicated GCD
1635D - Infinite Set
1462A - Favorite Sequence
1445B - Elimination
1656C - Make Equal With Mod
567A - Lineland Mail
1553A - Digits Sum
1359B - New Theatre Square
766A - Mahmoud and Longest Uncommon Subsequence
701B - Cells Not Under Attack
702A - Maximum Increase
1656D - K-good
1426A - Floor Number
876A - Trip For Meal
1326B - Maximums